package cn.jbolt.config.db;


import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import java.util.Date;

/**
 * mybatisplus的自动化填充
 */

public class JboltMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date.class, DateTime.now());
        // 如果有更新时需要自动填充的字段，可以在这里添加
        if (metaObject.hasSetter("updateTime")) {
            this.strictInsertFill(metaObject, "updateTime", Date.class, DateTime.now());
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 如果有更新时需要自动填充的字段，可以在这里添加
        if (metaObject.hasSetter("updateTime")) {
            this.strictInsertFill(metaObject, "updateTime", Date.class, DateTime.now());
        }
    }
}
